<template>
  <view class="home">
    <view class="home-top">
      <img src="../static/images/home/8c49085f8e973d9722c7e5234ff1dd5.png" style="width:100%;height:100%" />
    </view>
    <view class="home-title">
      <view>福彩</view>
      <img src="../static/images/home/3D.png" style="width:auto;height:30rpx" />
    </view>
    <view class="home-title">
      <view class="lq" @click="showCore">立即点击领取大师精准预测</view>
    </view>
    <view class="home-box">
      <view class="flex-home" style="margin-top:20rpx">
        <img src="../static/images/home/logo.png" style="width:50rpx;height:50rpx;margin-right:10rpx" />
        <view style="font-size: 30rpx; font-weight: 800;">福彩</view>
        <img src="../static/images/home/3D.png" style="width:auto;height:30rpx" />
        <view style="font-size: 30rpx; font-weight: 800;">免费精准预测</view>
      </view>

      <view style="margin-top: 30rpx;">
        <view class="flex-home" style="justify-content: space-between; font-weight: 800;">
          <view class="table-hr" style="width:140rpx">期数</view>
          <view class="table-hr">双胆</view>
          <view class="table-hr">独胆</view>
          <view class="table-hr" style="width:35%">直选</view>
          <view class="table-hr">开奖</view>
          <view class="table-hr">准错</view>
        </view>
        <view class="flex-home" style="justify-content: space-between; font-weight: 800;"  v-if="sumData">
          <view class="table-td" style="width:130rpx;overflow-y: hidden;">{{sumData}}期</view>
          <view class="table-td" style="width:85%; display: flex;align-items: center;color:red; justify-content: center;" @click="showCore">
            大师本期精准码已公开 点击获取微信 —>
            <img src="../static/images/home/wetcah.png" style="width:auto;height:40rpx;margin-left:15rpx" />
          </view>
        </view>
        <view v-for="(item,index) in list">
          <view class="flex-home" style="justify-content: space-between; font-weight: 800;">
            <view class="table-td" :style="{background:(index+1)%2==0?'#F5EFE3':'#FAFAFA'}" style="width:135rpx">{{item.periods}}期</view>
            <view class="table-td" :style="{background:(index+1)%2==0?'#F5EFE3':'#FAFAFA'}">{{item.doubleNum}}</view>
            <view class="table-td" :style="{background:(index+1)%2==0?'#F5EFE3':'#FAFAFA'}">{{item.singleNum}}</view>
            <view class="table-td" :style="{background:(index+1)%2==0?'#F5EFE3':'#FAFAFA'}" style="width:35%">{{item.directElection}}</view>
            <view class="table-td" :style="{background:(index+1)%2==0?'#F5EFE3':'#FAFAFA'}">{{item.ofLottery}}</view>
            <view class="table-td" :style="{background:(index+1)%2==0?'#F5EFE3':'#FAFAFA'}">{{item.misalignment==1?'准':'错'}}</view>
          </view>
        </view>
      </view>
      <view style="margin-top:20rpx;font-size:30rpx;line-height:45rpx;color:#68605d">
        本站拥有彩票权威大师与资深分析师团队，专为广大彩民提供福彩
        <img src="../static/images/home/3D.png" style="width:auto;height:30rpx" />
        和排列三“双飞”独胆”精准预测，到目前为止准确率高
        达
        <span style="color:red; font-weight: 800;">80%</span>以上。
      </view>

      <view class="home-title" style="color:#68605d;margin-top:40rpx;">
        <view>有兴趣进大师群聊面对面交流</view>
      </view>

      <view class="home-title" style="margin-top:40rpx;">
        <view class="lq" style="background: #F06E6C;padding:20rpx 35rpx; border-radius: 40rpx;" @click="showCore">立即点击加大师微信</view>
      </view>
      <view class="home-title" style="color:#EBBE8C;margin-top:40rpx;">
        <view>永久免费！机会稍纵即逝</view>
      </view>
      <view class="home-title" style="color:#3D3D3D;margin-top:10rpx;">
        <view @click="showCore">立即点击加大师微信</view>
      </view>
    </view>
    <uni-popup ref="popup" background-color="#fff">
      <view class="popup-content">
        <view style="justify-content: center;font-weight: 800;margin-bottom:20rpx;font-size:30rpx" class="flex-home">
          <img src="../static/images/home/wetcah.png" style="width:auto;height:40rpx;margin-right:10rpx" />
          长按保存微信
        </view>
        <img :src="wechatInFo.wechatCode" style="width:380rpx;height:380rpx" @longpress="saveImage" />
        <view style="text-align: center;margin:10rpx 0;fon t-size: 28rpx;font-weight: 800;">微信号：{{wechatInFo.wechatNum}}
		<view class="cp" @click="copyText(wechatInFo.wechatNum)">复制</view>
		</view>
      </view>
    </uni-popup>
  </view>
</template>
<script>
import { getwechat, getlist } from '@/api/system/user.js'
import config from '@/config.js'
import { getUrlParam } from '@/utils/utils'
export default {
  data() {
    return {
      show: false,
      list: [],
	  sumData:null,
      wechatInFo: {}
    }
  },
  onLoad(options) {},
  onShow() {},
  mounted() {
    getlist().then(res => {
      if (res.code == 200) {
        this.list = res.data
		if (res.data.length>0) {
			this.sumData= this.incrementStringNumber(res.data[0].periods) 
		} else{
			this.sumData=null
		}
      }
    })
  },
  computed: {},
  methods: {
	  copyText(text) {
	    uni.setClipboardData({
	      data: text,
	      success: function () {
	        // 可以添加用户友好的提示，例如使用uni.showToast提示复制成功
	        uni.showToast({
	          title: '复制成功',
	          icon: 'success',
	          duration: 2000
	        });
	      },
	      fail: function () {
	        console.log('复制失败');
	        // 可以添加错误处理或用户友好的提示
	      }
	    });
	  },
	  incrementStringNumber(str) {
	      // 将字符串转换为数值并加1
	      let incrementedNumber = parseInt(str, 10) + 1;
	      
	      // 将结果转换回字符串
	      let incrementedString = incrementedNumber.toString();
	      
	      // 确保前导零的数量不变
	      while (incrementedString.length < str.length) {
	          incrementedString = '0' + incrementedString;
	      }
	      
	      return incrementedString;
	  },
    async saveImage() {
      const imageUrl = this.wechatInFo.wechatCode
      try {
        const response = await fetch(imageUrl)
        const blob = await response.blob()

        // 创建一个URL对象
        const url = window.URL.createObjectURL(blob)

        // 创建一个a标签
        const a = document.createElement('a')
        a.href = url
        a.download = `wechat`
        // 触发点击事件
        a.click()

        // 释放URL对象
        window.URL.revokeObjectURL(url)
      } catch (error) {
        uni.showToast({
          title: '下载失败',
          icon: 'none',
          duration: 2000,
          mask: true
        })
      }
    },
    showCore() {
      let url = getUrlParam(window.location.href)
      if (url['id']) {
        getwechat({ id: url['id'] }).then(res => {
          if (res.code == 200 && res['data']) {
            res.data.wechatCode = config.baseUrl + res.data.wechatCode
            this.wechatInFo = res.data
			
            this.$refs.popup.open('center')
          } else {
            uni.showToast({
              title: '参数错误',
              duration: 2000,
              icon: 'none',
              mask: true
            })
          }
        })
      }
    }
  }
}
</script>

<style lang="scss">
img {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.cp{
	background: #09BB07;
	color: #fff;
	margin: 0 auto;
	width: 100rpx;
	border-radius: 30rpx;
	padding: 5rpx 10rpx;
	margin-top: 10rpx;
	
}
page {
  background: #ffffff;
}
.home-top {
  width: 100%;
  height: 300rpx;
}
.flex-home {
  display: flex;
  align-items: center;
}
.popup-content {
  width: 100%;
  padding: 20rpx 60rpx;
}
.home-title {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30rpx;
  font-weight: 800;
  margin-top: 25rpx;
}
.lq {
  color: #ffffff;
  background: #438eeb;
  padding: 10rpx 35rpx;
  border-radius: 30rpx;
  font-weight: 500;
  font-size: 28rpx;
}
.home-box {
  padding: 20rpx;
}
.table-hr {
  width: 13%;
  background: #ebebeb;
  height: 65rpx;
  margin: 5rpx;
  font-size: 26rpx;
  font-weight: 800;
  text-align: center;
  padding: 15rpx 5rpx;
}
.table-td {
  width: 13%;
  height: 65rpx;
  background: #f5efe3;
  margin: 5rpx;
  font-size: 26rpx;
  color: #68605d;
  font-weight: 800;
  text-align: center;
  padding: 15rpx 5rpx;
}
</style>